/*
 * @(#)AutoCompleteInputBoxTag.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.framework;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.dcivision.dms.core.AutoSuggestIndexValueManager;
import com.dcivision.dms.core.UserNameManager;

/**
 AutoCompleteInputBoxManagerFactory.java
 
 @author      Jim Zhou
 @company     DCIVision Limited
 @creation date   2006/09/19
 @version     $Revision: 1.3.2.2 $
 */

public class AutoCompleteInputBoxManagerFactory {
  
  private static Map boxTypeManagerMapping;
  private static AutoCompleteInputBoxManagerFactory instance = null;
  
  public static final String BOX_TYPE_USER_NAME = "userName";
  public static final String BOX_TYPE_INDEX_VALUE = "indexValue";
  
  private static final Log log = LogFactory.getLog(AutoCompleteInputBoxManagerFactory.class);
  /**
   * 
   */
  private AutoCompleteInputBoxManagerFactory() {
    super();
    
  }
  
  public static AutoCompleteInputBoxManagerFactory getInstance(){
    if (Utility.isEmpty(instance)) {
      init();
    }
    return instance;
  }
  
  /**
   * get autoCompleteInputBoxManager.
   * @param boxType          String
   * @return                 AutoCompleteInputBoxManager
   */
  public AutoCompleteInputBoxManager getAutoCompleteInputBoxManager(String boxType){
    return (AutoCompleteInputBoxManager)this.boxTypeManagerMapping.get(boxType);
  }
  
  /**
   * Initialize AutoCompleteInputBoxManagerFactory. 
   * Initialize all of boxType and AutoCompleteInputBoxManagerFactory
   */
  private static void init() {
    //add initialize this.boxTypeManagerMapping;
    /*
     * boxTypeManagerMapping.put(KEY,autoCompleteInputBoxManager);
     */
    try{
      boxTypeManagerMapping = new HashMap();
      boxTypeManagerMapping.put(AutoCompleteInputBoxManagerFactory.BOX_TYPE_USER_NAME,
          new UserNameManager());
      boxTypeManagerMapping.put(AutoCompleteInputBoxManagerFactory.BOX_TYPE_INDEX_VALUE,
          new AutoSuggestIndexValueManager());
    } catch (Exception e){
      log.error(e, e);
    }
    
    instance  = new AutoCompleteInputBoxManagerFactory();
  }
  
  /**
   * exist boxType.
   * @param boxType          String
   * @return                 boolean
   */
  public boolean getBoxTypeExists(String boxType){
    return this.boxTypeManagerMapping.containsKey(boxType);
  }
  
}
